/**
 * \file
 *
 * \brief Empty user application template
 *
 */

/**
 * \mainpage User Application template doxygen documentation
 *
 * \par Empty user application template
 *
 * Bare minimum empty user application template
 *
 * \par Content
 *
 * -# Include the ASF header files (through asf.h)
 * -# Minimal main function that starts with a call to board_init()
 * -# "Insert application code here" comment
 *
 */

/*
 * Include header files for all drivers that have been imported from
 * Atmel Software Framework (ASF).
 */
#include <asf.h>
#include "../Application/SpeakerRecog.h"
#include "Common.h"

#define	DATA_WINDOW_SIZE 		20
#define	DATA_WINDOW_SCALE		0.001	//1/1000


int main (void)
{
	
	/*Must come from somewhere*/
	double* pdAudioData = NULL;
	int iSampleRate = 8000; 
	long lWindowSize;
	double* pdAudioWindow = NULL;
	long lAudioDataSize = 0;
	/************************/
	
	long lWindowCounter=0;
	Handle hRecognition = NULL;
	double dProbability = 0;
		
	lWindowSize = iSampleRate*DATA_WINDOW_SIZE*DATA_WINDOW_SCALE;
	pdAudioWindow = pdAudioData;
	Bool8 bExtract = True8;
	
	/*Board initializing*/
	board_init();
	
	hRecognition = (Handle)SpeakerRecog_new(iSampleRate,lWindowSize);
	if(hRecognition)
	{
		while((lWindowSize/2)*(lWindowCounter+1) < lAudioDataSize)
		{
			if(SpeakerRecog_extractFeature(hRecognition,pdAudioWindow,lWindowSize)==True8)
			{
				pdAudioWindow=pdAudioWindow+(lWindowSize/2);
				lWindowCounter++;	
			}
			else
			{
				bExtract = False8;
			}
		}
		if(bExtract == True8)
		{
			/*Calculates the probability*/
			dProbability = SpeakerRecog_verify(hRecognition);
			//printf("Probability:%f",dProbability);			
		}
	}
}
